package sv.com.globalsolutionslt.convertidor;

import sv.com.globalsolutionslt.entidades.IdiomaPersona;
import sv.com.globalsolutionslt.controlador.IdiomaPersonaFacade;
import sv.com.globalsolutionslt.manejador.util.JsfUtil;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
/*
@FacesConverter(value = "idiomaPersonaConverter")
public class IdiomaPersonaConverter implements Converter {

    @Inject
    private IdiomaPersonaFacade ejbFacade;

    private static final String SEPARATOR = "#";
    private static final String SEPARATOR_ESCAPED = "\\#";

    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
        if (value == null || value.length() == 0 || JsfUtil.isDummySelectItem(component, value)) {
            return null;
        }
        return this.ejbFacade.encontrarPorID(getKey(value));
    }

    private sv.com.globalsolutionslt.entidades.IdiomaPersonaPK getKey(String value) {
        sv.com.globalsolutionslt.entidades.IdiomaPersonaPK key;
        String values[] = value.split(SEPARATOR_ESCAPED);
        key = new sv.com.globalsolutionslt.entidades.IdiomaPersonaPK();
        key.setIdIdioma(Integer.parseInt(values[0]));
        key.setIdPersona(Integer.parseInt(values[1]));
        return key;
    }
    private String getStringKey(sv.com.globalsolutionslt.entidades.IdiomaPersonaPK value) {
        StringBuffer sb = new StringBuffer();
        sb.append(value.getIdIdioma());
        sb.append(SEPARATOR);
        sb.append(value.getIdPersona());
        return sb.toString();
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null
                || (object instanceof String && ((String) object).length() == 0)) {
            return null;
        }
        if (object instanceof IdiomaPersona) {
            IdiomaPersona o = (IdiomaPersona) object;
            return getStringKey(o.getIdiomaPersonaPK());
        } else {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "object {0} is of type {1}; expected type: {2}", new Object[]{object, object.getClass().getName(), IdiomaPersona.class.getName()});
            return null;
        }
    }

}*/
